from django.db import models

# Create your models here.
class User(models.Model):     #用户表（User）
    userid = models.AutoField(primary_key=True)
    username = models.CharField(unique=True,max_length=50)
    password = models.CharField(max_length=10)
    role = models.IntegerField(choices=[(1,'管理员'),(2,'普通用户')])

class Book(models.Model):     #②　图书表（Book）
    bookid = models.AutoField(primary_key=True)
    title = models.CharField(unique=True,max_length=100)
    author = models.CharField(max_length=50)
    price = models.DecimalField(decimal_places=2,max_digits=10)
    stock = models.IntegerField(default=0)
    status = models.IntegerField(choices=[(1,'可借阅'),(2,'已下架')])

class Borrow(models.Model):   #③　借阅记录表（Borrow）
    borrowid = models.CharField(primary_key=True,max_length=50)
    book_id = models.ForeignKey(Book,on_delete=models.CASCADE,related_name='abc')
    user_id = models.ForeignKey(User,on_delete=models.CASCADE,related_name='efg')
    borrow_date = models.DateTimeField(auto_now_add=True)
    return_date = models.DateTimeField(auto_now_add=True)
    status = models.IntegerField(choices=[(1,'借阅中'),(2,'已归还'),(3,'超期未还')])